import 'package:flutter/material.dart';
import 'package:pabu/widget/component/component_page.dart';
import 'package:pabu/widget/device/device_page.dart';
import 'package:pabu/widget/plugin/plugin_page.dart';
import 'package:pabu/widget/request/request_page.dart';

class MainPage extends StatefulWidget {
  @override
  _MainPageState createState() => new _MainPageState();
}

class _MainPageState extends State<MainPage> {
  static const List<BottomNavigationBarItem> _bottomNavigationBarItems =
      <BottomNavigationBarItem>[
    BottomNavigationBarItem(
      icon: Icon(
        Icons.dashboard,
      ),
      title: Text(
        "组件",
      ),
    ),
    BottomNavigationBarItem(
      icon: Icon(
        Icons.favorite,
      ),
      title: Text(
        "请求",
      ),
    ),
    BottomNavigationBarItem(
      icon: Icon(
        Icons.person,
      ),
      title: Text(
        "插件",
      ),
    ),
    BottomNavigationBarItem(
      icon: Icon(
        Icons.person,
      ),
      title: Text(
        "系统",
      ),
    ),
  ];

  int _selectedIndex = 0;
  static List<Widget> _widgetOptions = <Widget>[
    ComponentPage(),
    RequestPage(),
    PluginPage(),
    DevicePage(),
  ];

  void _onItemTapped(int index) {
    setState(() {
      _selectedIndex = index;
    });
  }

  @override
  Widget build(BuildContext context) {
    return new Material(
      child: Scaffold(
        body: _widgetOptions.elementAt(_selectedIndex),
        bottomNavigationBar: BottomNavigationBar(
          // 底部按钮大于三个时
          type: BottomNavigationBarType.fixed,
          items: _bottomNavigationBarItems,
          currentIndex: _selectedIndex,
          onTap: _onItemTapped,
        ),
      ),
    );
  }
}
